from transformers import pipeline, AutoTokenizer
import os

os.environ['TRANSFORMERS_OFFLINE'] = "1"  # 放弃向huggingface联网访问。
# 示例文本列表
texts_to_translate = [
    "today is a good day",
    "你好啊",
]

# 指定模型的本地路径
model_name = r"D:\Downloads\opus-mt-zh-en"  # 请替换为实际路径
# 创建翻译管道，指定本地模型路径
pipe = pipeline("translation", model=model_name)
# 获取tokenizer，指定本地模型路径
tokenizer = AutoTokenizer.from_pretrained(model_name)
result = pipe(texts_to_translate)
print(result)

# pip install  -i https://pypi.tuna.tsinghua.edu.cn/simple
